**********************************************************************************
************Data Prep Master Do File for Transfer Pricing Project******************
**********************************************************************************

*Step 1: Fame Dataprep*

do "${hmrc_codedir}\dataprep\dataprep_fame" 

*Step 2: CT600 Dataprep and merge with fame*

do "${hmrc_codedir}\dataprep\dataprep_ct600" /*merge ct600 with fame and clean the data*/

do "${hmrc_codedir}\dataprep\dataprep_ct600_qualitycheck" /*merge ct600 with tax rate and creat a short version*/

*Step 3: Trade Statistics Dataprep*

do "${hmrc_codedir}\dataprep\dataprep_trade"

do "${hmrc_codedir}\dataprep\dataprep_trade_fy" /*correct the calendar year to fiscal year*/

*Step 4: Country characteristics data preperation

do "${hmrc_codedir}\dataprep\dataprep_CBT" 

do "${hmrc_codedir}\dataprep\exchange rate and differentiated goods"  /*differentiated goods and exchange rate:*/

*Step 5: Insheet and clean ownership data*

do "${hmrc_codedir}\dataprep\ownership_clean duplicate type"

*Step 6: create group_id for companies in ownership data*

do "${hmrc_codedir}\dataprep\ownership_groupid"

*Step 6: Merge CT600 with Trade Stats*

do "${hmrc_codedir}\dataprep\dataprep_ct600_trade_merge_fy"

*Step 7: Merge CT600 and Trade Stats with ownership and country level characteristics and differentiated good indicator*

do "${hmrc_codedir}\dataprep\prepare_export_fy_08032016" 

*Step 8: final dataprep for regression and iv regression

do "${hmrc_codedir}\dataprep\fulldata_prep4reg_fy" /*adding iv term. split samples*/

*step 9: count number of transaction for each trader commodity year

do "${hmrc_codedir}\dataprep\number of transaction" 

*step 10: add accounting period end months to each company

do "${hmrc_codedir}\dataprep\dataprep_ct600_ap" 

*step 11: adding labels:

do "${hmrc_codedir}\dataprep\adding label to var" 

*step 12: adding governance indicators:

do "${hmrc_codedir}\dataprep\data_prep_CBT_gov_ind"
do "${hmrc_codedir}\dataprep\wdi_prep"

*Step 13: adding taxable profit:
do "${hmrc_codedir}\dataprep\add_taxable profit"

*Step 14: adding leverage ratio and R&D expenditure:
do "${hmrc_codedir}\dataprep\add_leverage"
do "${hmrc_codedir}\dataprep\adding rd expenditure"

*adding R&D expenditure (group level):
do "${hmrc_codedir}\dataprep\adding group rd expenditure"

*adding tax haven
do "${hmrc_codedir}\dataprep\new_taxhaven"

*prepare a dataset that capture the dynamic ownership structure
do "${hmrc_codedir}\dataprep\dynamic_ownership"

